package day240110

import (
	"fmt"
	"time"
)

func M时间类型() {

	//var t time.Time
	//fmt.Println(t) //0001-01-01 00:00:00 +0000 UTC 无意义时间

	t := time.Now()        //当前时间
	fmt.Println("1情况:", t) //2024-01-10 15:41:12.336547 +0800 CST m=+0.001526301

	//通过纳秒时间戳创建时间变量
	t1 := time.Unix(0, t.UnixNano())
	fmt.Println("2情况:", t1) //2024-01-10 15:41:12 +0800 CST

	//自定义
	t2 := time.Date(2024, 1, 10, 15, 47, 0, 0, time.Local)
	fmt.Println("3情况:", t2) //2024-01-10 15:47:00 +0800 CST

	fmt.Println("4情况:", t2.Year()) //2024
	x, y, z := t.Date()
	fmt.Println("5情况:", x, y, z) //2024 January 10

	//时间差
	fmt.Println("6情况:", "时间差：", t2.Unix()) //秒差，以1970年1月1日秒差

	//格式时间
	fmt.Println("格式时间：----")
	test1()
}

// 格式时间
func test1() {
	now := time.Now()
	nowStr := now.Format("01/02 03:04:05PM '06 -0700")
	fmt.Println(nowStr)
	nowStr = now.Format("2006-January-02 03:04:05.999 pm")
	fmt.Println(nowStr)
	nowStr = now.Format("2006-Jan-02 03:04:05.999 pm")
	fmt.Println(nowStr)
	nowStr = now.Format("06-Jan-02 03:04:05.999 pm")
	fmt.Println(nowStr)
	nowStr = now.Format("006-Jan-02 03:04:05.999 pm")
	fmt.Println(nowStr)
	nowStr = now.Format("006-Jan-02 03:04:05.999 pm MST")
	fmt.Println(nowStr)
	nowStr = now.Format("006-Jan-02 03:04:05.999 pm -07")
	fmt.Println(nowStr)
	nowStr = now.Format("006-Jan-02 03:04:05.999 pm -070")
	fmt.Println(nowStr)
	nowStr = now.Format("006-Jan-02 03:04:05.999 pm mst")
	fmt.Println(nowStr)
	nowStr = now.Format("006-Jan-02 03:04:05.999 pm -07:00")
	fmt.Println(nowStr)

}
